<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
namespace org\copperforest\oak\authorization;

use \org\copperforest\oak as ct;

/**
 * Description of AuthenticatedUser
 *
 * @author agama
 */
class AuthenticatedUser extends User
{

    private $allPosibleRolSets = null;

    private function __construct( $id )
    {
        parent::__construct( $id );


        $this->allPosibleRolSets = RolSet::combinations( $this->rolSet );
    }

    static function getInstance()
    {
        if ( !isset( $_SESSION[ '_ct_auth_user_instance' ] ) )
                $_SESSION[ '_ct_auth_user_instance' ] = new AuthenticatedUser( $_SESSION->getUserId() );

        return $_SESSION[ '_ct_auth_user_instance' ];
    }

    function intersectRoles( $roles )
    {
        sort( $roles );

        return array_intersect( $this->rolSet, $roles );
    }

    function __sleep()
    {
        return array( 'id', 'rolSet', 'allPosibleRolSets' );
    }

}

?>
